package cn.sumpu.app.guoguojie.biz.impl;

import java.util.List;
import java.util.Map;
import org.springframework.transaction.annotation.Transactional;
import cn.sumpu.app.guoguojie.biz.FamilyTagBiz;
import cn.sumpu.app.guoguojie.dao.FamilyTagDao;
import cn.sumpu.app.guoguojie.dao.TagDao;
import cn.sumpu.app.guoguojie.domain.FamilyTag;
import cn.sumpu.app.guoguojie.domain.Tag;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class FamilyTagBizImpl implements FamilyTagBiz {

	private FamilyTagDao familyTagDao;
	private TagDao tagDao;


	public void setTagDao(TagDao tagDao) {
		this.tagDao = tagDao;
	}

	public void setFamilyTagDao(FamilyTagDao familyTagDao) {
		this.familyTagDao = familyTagDao;
	}

	@Override
	public void insertFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		familyTagDao.insertFamilyTag(familyTag);
	}
	
	@Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
	@Override
	public void insertFamilyTagList(String tag[], String doorplate) throws AppBusinessException{
		familyTagDao.deleteFamilyTagByFamily(doorplate);
		if(tag!=null){
			//添加的标签
			FamilyTag familyTag = null;
			for(String str:tag){
				familyTag = new FamilyTag();
				familyTag.setFamily(doorplate);
				familyTag.setTag(str);
				familyTagDao.insertFamilyTag(familyTag);
			}
		}
	}

	@Override
	public void deleteFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		familyTagDao.deleteFamilyTag(familyTag);
	}

	@Override
	public void updateFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		familyTagDao.updateFamilyTag(familyTag);
	}

	@Override
	public List<FamilyTag> getFamilyTagList(Map<String, Object> map)
			throws AppBusinessException {
		return familyTagDao.getFamilyTagList(map);
	}

	@Override
	public List<FamilyTag> getFamilyTagByDoorplate(String doorplate)
			throws AppBusinessException {
		return familyTagDao.getFamilyTagByDoorplate(doorplate);
	}

}
